package com.rp.upload.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rp.common.utils.RpUtil;
import com.rp.upload.dao.AttachmentDao;
import com.rp.upload.po.Attachment;

@Service
@Transactional
public class AttachmentService {

	@Autowired
	private AttachmentDao attachmentDao;
	
	/**
	 * 添加附件
	 * @param originalName 原始文件名
	 * @param generateName 生成的文件名
	 * @param description 描述
	 * @param fileSize 文件大小，转换为MB之后再传入吧
	 * @param fileType 文件类型，示例：.exe
	 * @param absolutePath 文件保存在服务器的绝对路径
	 * @param entityName 关联的实体名称
	 * @param entityId 关联的实体ID
	 * @return
	 */
	public String addAttachment(
			String originalName,
			String generateName,
			String description,
			double fileSize,
			String fileType,
			String absolutePath,
			String entityName,
			String entityId){
		
		Attachment atta = new Attachment();
		atta.setOriginalName(originalName);
		atta.setGenerateName(generateName);
		atta.setDescription(description);
		atta.setFileSize(fileSize);
		atta.setFileType(fileType);
		atta.setAbsolutePath(absolutePath);
		atta.setEntityName(entityName);
		atta.setEntityId(entityId);
		atta.setCreateDate(RpUtil.getCurrentDatetime());
		atta.setDownloadCount(0);
		
		return (String) attachmentDao.save(atta);
	}
	
}
